package com.yurun.dictionarymodule.service.Impl;

import com.github.pagehelper.PageHelper;
import com.yurun.commonapi.api.CommonResult;
import com.yurun.commonapi.pojo.Dictionary;
import com.yurun.dictionarymodule.mapper.DictionaryMapper;
import com.yurun.dictionarymodule.service.DictionaryService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DictionaryServiceImpl implements DictionaryService {


    @Autowired
    private DictionaryMapper dictionaryMapper;


    @Override
    public CommonResult getPositionOption(Dictionary dictionary) {
        List<Dictionary> list = dictionaryMapper.getAllDictionary(dictionary);
        List<Map<Integer, String>> result = new ArrayList<>();

        for (Dictionary temp : list) {
            Map<Integer, String> map = new HashMap<>();
            map.put(temp.getDictionaryKey(), temp.getDictionaryValue());
            result.add(map);
        }
        return CommonResult.success(result);
    }

    @Override
    public CommonResult getDictionaryList(BigInteger organizationId, BigInteger branchId, String keyword, int pageNum, int pageSize) {
        Dictionary dictionary = new Dictionary();
        dictionary.setOrganizationId(organizationId);
        dictionary.setBranchId(branchId);
        dictionary.setDictionaryName(keyword);
        PageHelper.startPage(pageNum, pageSize);
        return CommonResult.success(dictionaryMapper.getDictionaryList(dictionary));
    }
}
